package com.itheima.proxypool;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class test{
    public static void main(String[] args) {
        Student student = new Student();
        StudentInterface studentProxy = (StudentInterface) Proxy.newProxyInstance(student.getClass().getClassLoader(), new Class[]{StudentInterface.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                if ("study".equals(method.getName())) {
                    System.out.println("来黑马学习");
                    return null;
                } else {
                    return method.invoke(student, args);
                }
            }
        });
        studentProxy.eat("米饭");
        studentProxy.study();
    }
}
